package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.mapper.purchaseContractMapper;
import com.zygh.policeasset.pojo.PurchaseContract;
import com.zygh.policeasset.pojo.UploadFile;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/PurchaseContractService.class */
public class PurchaseContractService {
    @Autowired
    purchaseContractMapper purchaseContractMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;

    public PurchaseContract queryById(Integer id) {
        return this.purchaseContractMapper.queryById(id);
    }

    public PageInfo queryAll(int pageNum, int pageSize, String type, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo(this.purchaseContractMapper.queryAll(type, status));
    }

    public int add(PurchaseContract purchaseContract) {
        int count = this.purchaseContractMapper.add(purchaseContract);
        int projectId = purchaseContract.getId().intValue();
        List<UploadFile> uploadFileList = purchaseContract.getUploadFileList();
        for (int i = 0; i < uploadFileList.size(); i++) {
            uploadFileList.get(i).setProjectId(projectId);
            uploadFileList.get(i).setProjectName(purchaseContract.getPurchaseType());
            uploadFileList.get(i).setFileType(2);
            uploadFileList.get(i).setCreateDate(DateUtil.now());
            this.uploadFileMapper.add(uploadFileList.get(i));
        }
        return count;
    }

    public int update(PurchaseContract purchaseContract) {
        return this.purchaseContractMapper.update(purchaseContract);
    }

    public int deleteById(Integer id) {
        return this.purchaseContractMapper.deleteById(id);
    }

    public int updateByid(Integer id, Integer status) {
        return this.purchaseContractMapper.updateByid(id, status);
    }
}